package com.yaorange.config;

import com.yaorange.jobs.BackupMySQLJob;
import com.yaorange.jobs.ReleaseJob;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class QuartzConfig {


    @Bean
    public JobDetail backupMySQLJobDetail(){
        return JobBuilder.newJob(BackupMySQLJob.class).storeDurably().build();
    }

    @Bean
    public Trigger backupMySQLTrigger(){
        //准备执行计划
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 21 16 * * ? ");
        return TriggerBuilder.newTrigger()
                .forJob(backupMySQLJobDetail())
                .withSchedule(scheduleBuilder)
                .build();
    }


    //省略其他的JobDetail和Trigger配置


    //在完成客户分配到个人后：fllowDate（跟进时间）就存在一个日期值，存储分配到个人时的系统时间
    //跟进客户55天后将客户释放公共池中
    @Bean
    public JobDetail releaseJobDetail(){
        return JobBuilder.newJob(ReleaseJob.class).storeDurably().build();
    }
    @Bean
    public Trigger releaseTrigger(){
        //准备执行计划
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0 21 16 * * ? ");
        return TriggerBuilder.newTrigger()
                .forJob(releaseJobDetail())
                .withSchedule(scheduleBuilder)
                .build();
    }

}
